import Vue from 'vue'
import App from '@/App'
import router from '@/router'
import store from '@/store'
import request from '@/utils/request'

// element ui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'


//图像裁剪
import VueCropper from 'vue-cropper'
import '@/permission'
import '@/css/sideBar.scss'

// 第三方插件
import Cookies from 'js-cookie'
import '@/css/font-awesome-4.7.0/css/font-awesome.min.css'
import 'babel-polyfill'

// 语言文件
import zhLang from '@/lang/zh'
import enLang from '@/lang/en'

import Options from '@/options/base.js'
import * as filters from '@/utils/filter'
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.use(ElementUI, { locale: ((localStorage.getItem('lang') == 'en') ? enLocale : zhLocale) })
Vue.use(VueCropper)

Vue.prototype.store = store
Vue.prototype.request = request
Vue.prototype.Cookies = Cookies
Vue.prototype.Options = Options

Vue.config.productionTip = false
window.Promise = Promise

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
  data: {
    langType: 'zh', // 语言包，默认中文
  	lang: zhLang, // 语言包，默认中文
    defaultActive: '',
    fileUpload: 
      process.env.API_2 === '/'
      ? '/application/private/upload'
      : process.env.API_2 + '/application/private/upload'
  },
  created() {
  	this.checkLang()
  },
  methods: {
  	// 检查语言类型，初始化语言包
  	checkLang() {
      this.langType = ((this.getStorage('lang') ? this.getStorage('lang') : this.langType))
  		if(this.langType == 'en') {
  			this.lang = enLang
  		} else {
  			this.lang = zhLang
  		}
  	},
    optionProcess(option) {
      for(var i in option) {
        var item = option[i]
        if(!item && item!==0 && item!==false) {
          delete option[i]
        }
      }
      return option
    },
  	setStorage(key,value) {
  		localStorage.setItem(key,value)
  	},
  	getStorage(key) {
  		return localStorage.getItem(key)
  	},
  	removeStorage(key) {
  		localStorage.removeItem(key)
  	}
  }
})
